﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace Rizmar
{
    public partial class PesquisaSacadoForm : PesquisaBaseForm   // I see what you did there
    {
        public PesquisaSacadoForm(LancamentoForm obj)
        {
            lancamentoParent = obj;
            InitializeComponent();
        }

        private void PesquisaSacadoForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'rizmarDataSet.Sacado' table. You can move, or remove it, as needed.
            this.sacadoTableAdapter.Fill(this.rizmarDataSet.Sacado);

        }

        private void textBoxBusca_TextChanged(object sender, EventArgs e)
        {
            string selectCommand = "SELECT id, nome,documento FROM Sacado ";
            if (radioButtonNome.Checked)
                selectCommand += "WHERE nome LIKE '" + textBoxBusca.Text + "%'";
            else
                selectCommand += "WHERE documento LIKE '" + textBoxBusca.Text + "%'";

            SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCommand, ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataAdapter.Fill(table);
            sacadoBindingSource.DataSource = table;
            this.textBoxBusca.Focus();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            lancamentoParent.getUltimoTitulo().setSacadoTextBox(dataGridView.SelectedCells[0].OwningRow.Cells[1].Value.ToString());
            lancamentoParent.getUltimoTitulo().setLabelCodigoSacadoText(dataGridView.SelectedCells[0].OwningRow.Cells[0].Value.ToString());
            this.Close();
        }

       
    }
}
